#pragma once
#include "SmartArray.h"
#include "SmartString.h"

#ifndef NULL
#define NULL 0
#endif

#include <iostream>
#define cairo_color(a) ((a)/(static_cast<double>(0xFF)))

using std::cout;
using std::endl;
typedef unsigned char byte;

class Color:public SmartObject
{
	private:
		struct
		{
			unsigned int dummy: 1;
			unsigned int red: 5;
			unsigned int green: 5;
			unsigned int blue: 5;
		} _RGB;
		byte round(byte);
	public:
		Color();
		SmartObject_Type_Information("Palette")
		byte Red() const;
		byte Green() const;
		byte Blue() const;
		byte Red(byte);
		byte Green(byte);
		byte Blue(byte);
		Color& operator = ( unsigned int );
		Color& operator = (unsigned short);
		Color& operator = ( Color&);
		operator int();
		operator short();
};

class Palette:public SmartArray<Color>
{
	private:
		SmartString name;
	public:
		SmartObject_Type_Information("Palette")
		Color& operator [] ( int) const;
		Palette& operator = ( Palette&);
		void ExportToFile(std::ostream&);
		void LoadFromFile(std::istream&);
		Palette(const char*);
		const SmartString& Name() const;
};

class PaletteFormat:public SmartObject
{
protected:
	SmartString mDesc,mArguments;
public:
	SmartObject_Type_Information("Palette Format")
	PaletteFormat(const char* ="No Description Available.");
	const SmartString& Description() const;
	const SmartArray<SmartString> Arguments() const;
	virtual void Save( const Palette&, const SmartArray<SmartString>&) =0;
	virtual void Open( Palette&, const SmartArray<SmartString>&) =0;
};
